//
//  YLForgetPasswordViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/17.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "YLForgetPasswordViewController.h"
#import "VerificationCodeBtn.h"
#import "YLPasswordResetViewController.h"
@interface YLForgetPasswordViewController ()
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UIView *bottomView;
@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *codeTf;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;

@property (weak, nonatomic) IBOutlet VerificationCodeBtn *codeBtn;
@property(nonatomic,copy)NSString *radCode;
@end

@implementation YLForgetPasswordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setCorder:self.topView];
    [self setCorder:self.bottomView];
    [self setCorder:self.nextBtn];
    // Do any additional setup after loading the view from its nib.
}

-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"安全验证";
    self.view.backgroundColor = [UIColor whiteColor];
    self.codeBtn.layer.cornerRadius = 15;
    self.codeBtn.layer.masksToBounds = YES;
//    __block VerificationCodeBtn *blockBtn = self.codeBtn;
//        [blockBtn startTimer];
    WS(weakSelf)
//    self.codeBtn.clickblock = ^{
//        [blockBtn startTimer];
//        //获取手机的验证码
//    };
    [self.codeBtn addTarget:self action:@selector(startGetVercode:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)startGetVercode:(UIButton *)btn{
    if (![NSString checkTelNumber:self.phoneTF.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入正确的手机号"];
        return;
    }
    [self.codeBtn startTimer];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:self.phoneTF.text,@"TelCode", nil];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:sendPhoneCode header:nil parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        NSString *message = responseObject[@"result"][@"message"];
        [SVProgressHUD showInfoWithStatus:@"验证码发送成功"];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
-(void)setCorder:(UIView *)view{
    view.layer.cornerRadius = 23;
    view.layer.masksToBounds = YES;
    if ([view isKindOfClass:[UIButton class]]) {
        return;
    }
    view.layer.borderWidth = 1;
    view.layer.borderColor = COLOR_HEX(0xE0E0E0).CGColor;
}
- (IBAction)nextAction:(id)sender {
    if ([NSString isBlankString:self.phoneTF.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入手机号"];
        return;
    }
    if ([NSString isBlankString:self.codeTf.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入验证号"];
        return;
    }
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:self.phoneTF.text,@"TelCode",self.codeTf.text,@"RadCode", nil];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:comparePhoneCode header:[LKUserInforTool header] parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        

        if ([NSString isBlankString:responseObject[@"verificationCode"]]) {
        [SVProgressHUD showInfoWithStatus:responseObject[@"successOrFailure"]];
            return ;
        }
        YLPasswordResetViewController *vc = [[YLPasswordResetViewController alloc] init];
        vc.telCode = self.phoneTF.text;
        vc.vericode = responseObject[@"verificationCode"];
        [self.navigationController pushViewController:vc animated:YES];
        
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
